package link.xieyu.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import link.xieyu.pojo.AppNoticed;
import link.xieyu.service.AppNoticedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author xieyu
 */
@Api(tags = "app关注相关接口")
@RestController
@RequestMapping("app/noticed")
public class AppNoticedController extends BaseController {
    @Autowired
    private AppNoticedService appNoticedService;

    @ApiOperation("获取粉丝列表")
    @GetMapping("findFans")
    public ResponseEntity<Object> findFans(@ApiParam("用户名") String keyword, @ApiParam("排序0默认1总额2次数") Integer sort) {
        return new ResponseEntity<>(
                appNoticedService.findFans(getUser().getId(), keyword, sort), HttpStatus.OK);
    }

    @ApiOperation("获取关注列表")
    @GetMapping("findAttention")
    public ResponseEntity<Object> findAttention() {
        return new ResponseEntity<>(appNoticedService.findAttention(getUser().getId()), HttpStatus.OK);
    }

    @ApiOperation("添加关注")
    @PostMapping("{id}")
    public ResponseEntity<Object> addNoticed(@ApiParam("被关住人id") @PathVariable Integer id) {
        appNoticedService.addNoticed(AppNoticed.builder().beNoticed(id).source("默认").userId(getUser().getId()).build());
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @ApiOperation("取消关注")
    @DeleteMapping("{id}")
    public ResponseEntity<Object> delNoticed(@ApiParam("被关住人id") @PathVariable Integer id) {
        appNoticedService.delNoticed(getUser().getId(), id);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @ApiOperation("作者封禁/解封该粉丝")
    @PutMapping("{id}")
    public ResponseEntity<Object> prohibit(@ApiParam("粉丝id") @PathVariable Integer id) {
        appNoticedService.prohibit(getUser().getId(), id);
        return new ResponseEntity<>(HttpStatus.OK);
    }

}
